package javafx.demo.chart;

import java.util.Arrays;

import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import javafx.util.Duration;

public class StackedBarChartSample extends Application {

	final static String austria = "Austria";
	final static String brazil = "Brazil";
	final static String france = "France";
	final static String italy = "Italy";
	final static String usa = "USA";
	final CategoryAxis xAxis = new CategoryAxis();
	final NumberAxis yAxis = new NumberAxis();
	final StackedBarChart<String, Number> sbc = new StackedBarChart<>(xAxis, yAxis);
	final XYChart.Series<String, Number> series1 = new XYChart.Series<>();
	final XYChart.Series<String, Number> series2 = new XYChart.Series<>();
	final XYChart.Series<String, Number> series3 = new XYChart.Series<>();

	@Override
	public void start(Stage stage) {
		stage.setTitle("Bar Chart Sample");
		sbc.setTitle("Country Summary");
		xAxis.setLabel("Country");
		xAxis.setCategories(FXCollections.<String> observableArrayList(Arrays.asList(austria, brazil, france, italy,
				usa)));
		yAxis.setLabel("Value");
		series1.setName("2003");
		series1.getData().add(new XYChart.Data<>(austria, 25601.34));
		series1.getData().add(new XYChart.Data<>(brazil, 20148.82));
		series1.getData().add(new XYChart.Data<>(france, 10000));
		series1.getData().add(new XYChart.Data<>(italy, 35407.15));
		series1.getData().add(new XYChart.Data<>(usa, 12000));
		series2.setName("2004");
		series2.getData().add(new XYChart.Data<>(austria, 57401.85));
		series2.getData().add(new XYChart.Data<>(brazil, 41941.19));
		series2.getData().add(new XYChart.Data<>(france, 45263.37));
		series2.getData().add(new XYChart.Data<>(italy, 117320.16));
		series2.getData().add(new XYChart.Data<>(usa, 14845.27));
		series3.setName("2005");
		series3.getData().add(new XYChart.Data<>(austria, 45000.65));
		series3.getData().add(new XYChart.Data<>(brazil, 44835.76));
		series3.getData().add(new XYChart.Data<>(france, 18722.18));
		series3.getData().add(new XYChart.Data<>(italy, 17557.31));
		series3.getData().add(new XYChart.Data<>(usa, 92633.68));
		Scene scene = new Scene(sbc, 800, 600);
		sbc.getData().addAll(series1, series2, series3);
		stage.setScene(scene);
		stage.show();

	}

	public static void main(String[] args) {
		launch(args);
	}
}